package com.euq.controller;

import com.euq.entity.Role;
import com.euq.log.BusinessLog;
import com.euq.log.Log;
import com.euq.node.ZTreeNode;
import com.euq.service.RoleService;
import com.euq.utils.SecurityUtils;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/role")
public class RoleController {
    private static final Logger log= LoggerFactory.getLogger(RoleController.class);
    @Autowired
    private RoleService roleService;
    @GetMapping("/list")
    public PageInfo<Role> listAll(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int size) {
        return roleService.listAll(page,size);
    }
    @PostMapping("/delete")
    @BusinessLog(logName = "删除角色",logType = "业务日志")
    public void delete(@RequestBody Long id){
        log.info("用户{}删除角色", SecurityUtils.getCurrentUser());
        roleService.delete(id);
    }
    @PostMapping("/select")
    public PageInfo<Role> select(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "5") int size,String name,String tips){
        return roleService.selectRoles(page,size,name,tips);
    }
    @GetMapping("/tree")
    public ResponseEntity<?> getRoleTree() {
        List<ZTreeNode> treeNodes = roleService.getRoleTreeNodes();
        return ResponseEntity.ok(treeNodes);
    }
    @PostMapping("/save")
    @BusinessLog(logName = "编辑角色",logType = "业务日志")
    public void save(String name ,String tips,Long deptId,Long pid,int num){
        log.info("用户{}编辑{}角色信息",SecurityUtils.getCurrentUser(),name);
        roleService.save(name,tips,deptId,pid,num);
    }
}
